import { defineStore } from "pinia";
import { DesktopSharp, FilmSharp,GameController,Map } from '@vicons/ionicons5';
import { controlWindow } from '@/utils/window';

type Theme = 'light' | 'dark';
type Lang = 'zhCn' | 'en';
export interface WindowItem {
    id: keyof typeof PAGELABEL;
    isOpen: boolean;
    icon: any; // 如果知道具体类型可以更精确
}
const PAGELABEL = {
    FRONTEND:'bp-frontend',//前台页面
    TRANSITION:'bp-transition', //过渡画面
    SCORE:'bp-score', //比分板窗口
    MAP:'bp-map', //地图窗口
}

export const useAppStore = defineStore('appStore', {
    state: () => ({
        theme: 'light',
        version: 'v0.1.0',
        lang: 'zhCn',
        windowList: [
            {
                id: PAGELABEL.FRONTEND,
                isOpen: false,
                icon: DesktopSharp
            },
            {
                id: PAGELABEL.TRANSITION,
                isOpen: false,
                icon: FilmSharp
            },
            {
                id: PAGELABEL.SCORE,
                isOpen: false,
                icon: GameController
            },
            {
                id: PAGELABEL.MAP,
                isOpen: false,
                icon: Map
            }
        ] as WindowItem[]
    }),
    actions: {
        setThemeMode(theme: Theme) {
            this.theme = theme;
        },
        setVersion(version: string) {
            this.version = version;
        },
        setLangMode(lang: Lang) {
            this.lang = lang;
        },
        changeWindowState(id: string) {
            this.$patch( (state) => {
                const win = state.windowList.find(item => item.id === id);
                if (win) {
                    const type = win.isOpen ? 'hide' : 'show';
                    controlWindow(id, type).then(()=>{
                        win.isOpen = !win.isOpen;
                    })
                }
            });
        },
        clearWindow(id: string){
            this.$patch( (state) => {
                const win = state.windowList.find(item => item.id === id);
                if (win) {
                    controlWindow(id, 'hide').then(()=>{
                        win.isOpen = false;
                    })
                }
            });
        },
    }
})

